package com.Cychat.post.controller;


import com.Cychat.commons.entity.ResultMessage;
import com.Cychat.commons.entity.pojo.Favorite;
import com.Cychat.post.entity.dto.FavoriteDTO;
import com.Cychat.post.entity.vo.FavoriteVO;
import com.Cychat.post.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: 崔航
 * @Date: 2025/11/3:11:56
 * @Description:
 */
@RestController
@RequestMapping("/api/post/favorite")
@CrossOrigin
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;
    @GetMapping("/selectPostFavorites/{userId}")
    public ResultMessage selectPostFavorites(@PathVariable("userId") Long userId){
        List<FavoriteDTO> favoriteDTOList = favoriteService.selectPostFavorites(userId);
        return ResultMessage.success(favoriteDTOList);
    }
    @PostMapping("/addFavorite/{userId}")
    public ResultMessage addFavorite(@RequestBody FavoriteVO favoriteVo,@PathVariable("userId") Long userId){
        favoriteService.addFavorite(favoriteVo.getUserId(), favoriteVo.getTargetId());
        return ResultMessage.success("收藏成功");
    }
    @DeleteMapping("/deleteFavorite/{userId}")
    public ResultMessage deleteFavorite(@RequestBody FavoriteVO favoriteVo,@PathVariable("userId") Long userId){
        favoriteService.deleteFavorite(favoriteVo.getUserId(), favoriteVo.getTargetId());
        return ResultMessage.success("取消收藏成功");
    }
}
